package com.efounder.frame.utils;

import android.content.Context;
import android.content.Intent;

import java.util.HashMap;
import java.util.Map;

/**
 * 注册urlscheme管理
 * Created by yqs97.
 * Date: 2019/10/17
 * Time: 13:57
 */
public class UrlSchemeFactory {
    private static UrlSchemeFactory urlSchemeFactory = new UrlSchemeFactory();
    private Map<String, IScheme> schemeMap = new HashMap<>();

    private String schemeTypeKey = "type";

    public static UrlSchemeFactory getInstance() {
        return urlSchemeFactory;
    }

    public IScheme getScheme(String type) {
        return schemeMap.get(type);
    }

    /**
     * 注册处理该type的 scheme类
     * @param type
     * @param scheme
     */
    public void registerScheme(String type, IScheme scheme) {
        schemeMap.put(type, scheme);
    }


    public String getSchemeTypeKey() {
        return schemeTypeKey;
    }

    public void setSchemeTypeKey(String schemeTypeKey) {
        this.schemeTypeKey = schemeTypeKey;
    }

    public interface IScheme {

        /**
         * 执行动作
         * 业务系统可以在这个方法下执行跳转页面等业务逻辑
         *
         * @param schemeIntent
         */
        void doActioin(Context context, Intent schemeIntent);
    }
}
